package org.quickserver.net.SHZC.control;

import com.dykj.fireFighting.web.model.report.DevHisZc;
import org.quickserver.net.model.ZCServerData;
import org.quickserver.net.server.ClientHandler;
import org.quickserver.util.data.dataProcessing;
import org.quickserver.util.state.ZC2B0State;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

public class ZC6B0 {
    public ZC6B0()
    {
    }

    public static DevHisZc ZC6B0OBJ(ClientHandler handler, String strs[], int dataLength) throws ParseException {
        DevHisZc devHisZc=new DevHisZc();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(strs.length);
        ZCServerData ec = (ZCServerData)handler.getClientData();
        int ml=dataProcessing.hexStringToInt10(strs[0]);//指令类型
        System.out.println("ml------"+ml);
        int lxbz=dataProcessing.sumHexStringToInt10(strs[2],strs[1]); //类型标志
        System.out.println("类型标志------"+lxbz+"---------"+strs[2]+"----"+strs[1]);
        devHisZc.setLxbz(lxbz+"");
        int bjbm=dataProcessing.sumHexStringToInt10(strs[4],strs[3]); //部件编码
        System.out.println("部件编码------"+bjbm+"---------"+strs[4]+"----"+strs[3]);
        devHisZc.setBjbm(bjbm+"");
        int xhqd=dataProcessing.sumHexStringToInt10(strs[6],strs[5]); //信号强度
        System.out.println("信号强度------"+xhqd+"---------"+strs[6]+"----"+strs[5]);
        devHisZc.setXhqd(xhqd+"");
        int xhzldj=dataProcessing.sumHexStringToInt10(strs[8],strs[7]); //信号质量等级
        System.out.println("信号质量等级------"+xhzldj+"---------"+strs[8]+"----"+strs[7]);
        devHisZc.setXhzldj(xhzldj+"");
        int xzb=dataProcessing.sumHexStringToInt10(strs[10],strs[9]); //信噪比
        System.out.println("信噪比------"+xzb+"---------"+strs[10]+"----"+strs[9]);
        devHisZc.setXzb(xzb+"");
        int xhfgdjEcl=dataProcessing.hexStringToInt10(strs[11]); //信号覆盖等级 ECL
        System.out.println("信号覆盖等级 ECL------"+xhfgdjEcl+"---------"+strs[11]);
        devHisZc.setXhfgdjecl(xhfgdjEcl+"");
        int ld=dataProcessing.sumHexStringToInt10(strs[13],strs[12]); //漏电
        System.out.println("漏电------"+ld+"---------"+strs[13]+"----"+strs[12]);
        devHisZc.setLd(ld+"");
        String[] zygdls={strs[14],strs[15],strs[16],strs[17]};
        byte[] zygdlsByte=dataProcessing.hexStringsToByteArray(zygdls);
        int zygdl=dataProcessing.bytesToIntBig(zygdlsByte,0); //总有功电量
        System.out.println("总有功电量------"+zygdl*0.01+"Kwh");
        double zygdlD=dataProcessing.multiplication(zygdl,0.01,2);
        devHisZc.setZygdl(zygdlD+"");
        int dya=dataProcessing.sumHexStringToInt10(strs[19],strs[18]); //电压A
        System.out.println("电压A------"+dya*0.01+"V---------"+strs[19]+"----"+strs[18]);
        double dyaD=dataProcessing.multiplication(dya,0.01,2);
        devHisZc.setDya(dyaD+"");

        int dyb=dataProcessing.sumHexStringToInt10(strs[21],strs[20]); //电压B
        System.out.println("电压B------"+dyb*0.01+"V---------"+strs[21]+"----"+strs[20]);
        double dybD=dataProcessing.multiplication(dyb,0.01,2);
        devHisZc.setDyb(dybD+"");
        int dyc=dataProcessing.sumHexStringToInt10(strs[23],strs[22]); //电压C
        System.out.println("电压C------"+dyc*0.01+"V---------"+strs[23]+"----"+strs[22]);
        double dycD=dataProcessing.multiplication(dyc,0.01,2);
        devHisZc.setDyc(dycD+"");

        int dla=dataProcessing.sumHexStringToInt10(strs[25],strs[24]); //电流A
        System.out.println("电流A------"+dla*0.1+"A---------"+strs[25]+"----"+strs[24]);
        double dlaD=dataProcessing.multiplication(dla,0.1,1);
        devHisZc.setDla(dlaD+"");
        int dlb=dataProcessing.sumHexStringToInt10(strs[27],strs[26]); //电流B
        System.out.println("电流B------"+dlb*0.1+"A---------"+strs[27]+"----"+strs[26]);
        double dlbD=dataProcessing.multiplication(dlb,0.1,1);
        devHisZc.setDlb(dlbD+"");

        int dlc=dataProcessing.sumHexStringToInt10(strs[29],strs[28]); //电流C
        System.out.println("电流C------"+dlc*0.1+"A---------"+strs[29]+"----"+strs[28]);
        double dlcD=dataProcessing.multiplication(dlc,0.1,1);
        devHisZc.setDlc(dlcD+"");
        int wda=dataProcessing.sumHexStringToInt10(strs[31],strs[30]); //温度A
        System.out.println("温度A------"+wda+"------"+wda*0.1+"℃---------"+strs[31]+"----"+strs[30]);
        double wdaD=dataProcessing.multiplication(wda,0.1,1);
        devHisZc.setWda(wdaD+"");

        int wdb=dataProcessing.sumHexStringToInt10(strs[33],strs[32]); //温度B
        System.out.println("温度B------"+wdb*0.1+"℃---------"+strs[33]+"----"+strs[32]);
        double wdbD=dataProcessing.multiplication(wdb,0.1,1);
        devHisZc.setWdb(wdbD+"");
        int wdc=dataProcessing.sumHexStringToInt10(strs[35],strs[34]); //温度C
        System.out.println("温度C------"+wdc*0.1+"℃---------"+strs[35]+"----"+strs[34]);
        double wdcD=dataProcessing.multiplication(wdc,0.1,1);
        devHisZc.setWdc(wdcD+"");
        int wdn=dataProcessing.sumHexStringToInt10(strs[37],strs[36]); //温度N
        System.out.println("温度N------"+wdn*0.1+"℃---------"+strs[37]+"----"+strs[36]);
        double wdnD=dataProcessing.multiplication(wdn,0.1,1);
        devHisZc.setWdn(wdnD+"");

        String componentState[] = new String[7];
        componentState[0] = strs[38];
        componentState[1] = strs[39];
        componentState[2] = strs[40];
        componentState[3] = strs[41];
        componentState[4] = strs[42];
        componentState[5] = strs[43];
        componentState[6] = strs[44];
        Map<String, String> map= ZC2B0State.getZC2B0State(componentState);
        devHisZc.setComponentStateMap(map);
        System.out.println(map);
        String[] abxdys={strs[45],strs[46],strs[47],strs[48]};
        byte[] abxdyByte=dataProcessing.hexStringsToByteArray(abxdys);
        int abxdy=dataProcessing.bytesToIntBig(abxdyByte,0); //AB 线电压
        double abxdyD=dataProcessing.multiplication(abxdy,0.1,1);
        System.out.println("AB 线电压---|||---"+dataProcessing.multiplication(abxdy,0.1,1));
        devHisZc.setAbxdy(abxdyD+"");

        String[] bcxdys={strs[49],strs[50],strs[51],strs[52]};
        byte[] bcxdyByte=dataProcessing.hexStringsToByteArray(bcxdys);
        int bcxdy=dataProcessing.bytesToIntBig(bcxdyByte,0); //BC 线电压
        double bcxdyD=dataProcessing.multiplication(bcxdy,0.1,1);
        System.out.println("BC 线电压------"+bcxdyD+"V");
        devHisZc.setBcxdy(bcxdyD+"");
        String[] caxdys={strs[53],strs[54],strs[55],strs[56]};
        byte[] caxdyByte=dataProcessing.hexStringsToByteArray(caxdys);
        int caxdy=dataProcessing.bytesToIntBig(caxdyByte,0); //CA 线电压
        double caxdyD=dataProcessing.multiplication(caxdy,0.1,1);
        System.out.println("CA 线电压------"+caxdyD+"V");
        devHisZc.setCaxdy(caxdyD+"");
        String[] abxdls={strs[57],strs[58],strs[59],strs[60]};
        byte[] abxdlByte=dataProcessing.hexStringsToByteArray(abxdls);
        int abxdl=dataProcessing.bytesToIntBig(abxdlByte,0); //AB 线电流
        double abxdlD=dataProcessing.multiplication(abxdl,0.001,3);
        System.out.println("AB 线电流------"+abxdlD+"A");
        devHisZc.setAbxdl(abxdlD+"");
        String[] bcxdls={strs[61],strs[62],strs[63],strs[64]};
        byte[] bcxdlByte=dataProcessing.hexStringsToByteArray(bcxdls);
        int bcxdl=dataProcessing.bytesToIntBig(bcxdlByte,0); //BC 线电流
        double bcxdlD=dataProcessing.multiplication(bcxdl,0.001,3);
        System.out.println("BC 线电流------"+bcxdlD+"A");
        devHisZc.setBcxdl(bcxdlD+"");

        String[] caxdls={strs[65],strs[66],strs[67],strs[68]};
        byte[] caxdlByte=dataProcessing.hexStringsToByteArray(caxdls);
        int caxdl=dataProcessing.bytesToIntBig(caxdlByte,0); //CA 线电流
        double caxdlD=dataProcessing.multiplication(caxdl,0.001,3);
        System.out.println("CA 线电流------"+caxdlD+"A");
        devHisZc.setCaxdl(caxdlD+"");

        String[] axyggls={strs[69],strs[70],strs[71],strs[72]};
        byte[] axygglByte=dataProcessing.hexStringsToByteArray(axyggls);
        int axyggl=dataProcessing.bytesToIntBig(axygglByte,0); //A 相有功功率
        double axygglD=dataProcessing.multiplication(axyggl,0.001,3);
        System.out.println("A 相有功功率------*"+axygglD+"KW");
        devHisZc.setAxyggl(axygglD+"");

        String[] bxyggls={strs[73],strs[74],strs[75],strs[76]};
        byte[] bxygglByte=dataProcessing.hexStringsToByteArray(bxyggls);
        int bxyggl=dataProcessing.bytesToIntBig(bxygglByte,0); //B 相有功功率
        double bxygglD=dataProcessing.multiplication(bxyggl,0.001,3);
        System.out.println("B 相有功功率------*"+bxygglD+"KW");
        devHisZc.setBxyggl(bxygglD+"");
        String[] cxyggls={strs[77],strs[78],strs[79],strs[80]};
        byte[] cxygglByte=dataProcessing.hexStringsToByteArray(cxyggls);
        int cxyggl=dataProcessing.bytesToIntBig(cxygglByte,0); //C 相有功功率
        double cxygglD=dataProcessing.multiplication(cxyggl,0.001,3);
        System.out.println("C 相有功功率------*"+cxygglD+"KW");
        devHisZc.setCxyggl(cxygglD+"");
        String[] zyggls={strs[81],strs[82],strs[83],strs[84]};
        byte[] zygglByte=dataProcessing.hexStringsToByteArray(zyggls);
        int zyggl=dataProcessing.bytesToIntBig(zygglByte,0); //总有功功率
        double zygglD=dataProcessing.multiplication(zyggl,0.001,3);
        System.out.println("总有功功率------*"+zygglD+"KW");
        devHisZc.setZyggl(zygglD+"");
        String[] axwggls={strs[85],strs[86],strs[87],strs[88]};
        byte[] axwgglByte=dataProcessing.hexStringsToByteArray(axwggls);
        int axwggl=dataProcessing.bytesToIntBig(axwgglByte,0); //A 相无功功率
        double axwgglD=dataProcessing.multiplication(axwggl,0.001,3);
        System.out.println("A 相无功功率------*"+axwgglD+"KW");
        devHisZc.setAxwggl(axwgglD+"");



        String[] bxwggls={strs[89],strs[90],strs[91],strs[92]};
        byte[] bxwgglByte=dataProcessing.hexStringsToByteArray(bxwggls);
        int bxwggl=dataProcessing.bytesToIntBig(bxwgglByte,0); //B 相无功功率
        double bxwgglD=dataProcessing.multiplication(bxwggl,0.001,3);
        System.out.println("B 相无功功率------*"+bxwgglD+"KW");
        devHisZc.setBxwggl(bxwgglD+"");
        String[] cxwggls={strs[93],strs[94],strs[95],strs[96]};
        byte[] cxwgglByte=dataProcessing.hexStringsToByteArray(cxwggls);
        int cxwggl=dataProcessing.bytesToIntBig(cxwgglByte,0); //C 相无功功率
        double cxwgglD=dataProcessing.multiplication(cxwggl,0.001,3);
        System.out.println("C 相无功功率------*"+cxwgglD+"KW");
        devHisZc.setCxwggl(cxwgglD+"");
        String[] zwggls={strs[97],strs[98],strs[99],strs[100]};
        byte[] zwgglByte=dataProcessing.hexStringsToByteArray(zwggls);
        int zwggl=dataProcessing.bytesToIntBig(zwgglByte,0); //总无功功率
        double zwgglD=dataProcessing.multiplication(zwggl,0.001,3);
        System.out.println("总无功功率------*"+zwgglD+"KW");
        devHisZc.setZwggl(zwgglD+"");

        int[] glfx=dataProcessing.henTo2(strs[101]);//总有功/无功功率方向
        String  ygfx="";//有功方向
        String  wgfx="";//无功方向
        if(glfx[0]==0){
            ygfx="正向";
        }else if(glfx[0]==1){
            ygfx="反向";
        }
        if(glfx[1]==0){
            wgfx="正向";
        }else if(glfx[1]==1){
            wgfx="反向";
        }
        devHisZc.setYgglfx(ygfx);
        devHisZc.setWgglfx(wgfx);
        System.out.println("有功方向-----"+ygfx);
        System.out.println("无功方向-----"+wgfx);

        int glys=dataProcessing.sumHexStringToInt10(strs[103],strs[102]); //功率因数
        double glysD=dataProcessing.multiplication(glys,0.0001,4);
        System.out.println("功率因数------"+glysD);
        devHisZc.setGlys(glysD+"");
        int pl=dataProcessing.sumHexStringToInt10(strs[105],strs[104]); //频率
        double plD=dataProcessing.multiplication(pl,0.01,2);
        System.out.println("频率------"+pl*0.01+"Hz");
        devHisZc.setPl(plD+"");
        String[] zwgdls={strs[109],strs[108],strs[107],strs[106]};
        byte[] zwgdlByte=dataProcessing.hexStringsToByteArray(zwgdls);
        int zwgdl=dataProcessing.bytesToIntLittle(zwgdlByte,0); //总无功电量
        double zwgdlD=dataProcessing.multiplication(zwgdl,0.01,2);
        System.out.println("总无功电量------"+zwgdlD+"Kvarh");
        devHisZc.setZwgdl(zwgdlD+"");

        String stateTime[] = new String[6];
        stateTime[0] = strs[110];
        stateTime[1] = strs[111];
        stateTime[2] = strs[112];
        stateTime[3] = strs[113];
        stateTime[4] = strs[114];
        stateTime[5] = strs[115];
        devHisZc.setUpTime(sdf.parse(dataProcessing.strsToTime(stateTime)));
        devHisZc.setId(ec.getUniqueCode());
        devHisZc.setDevCode(ec.getUniqueCode());
        return devHisZc;
    }
}
